home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Basic Classes / Z Sources / ZClipboard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-17  |  6.3 KB  |  250 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp    -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZClipboard.cpp    -- the clipboard object
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1997, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #include    "MacZoop.h"
  23.  
  24.  
  25. ZClipboard*    gClipboard = NULL;
  26.  
  27.  
  28. /*----------------------------------***  PUTDATA  ***-----------------------------------*/
  29. /*    
  30. put the handle on the clipboard with the type supplied
  31. ----------------------------------------------------------------------------------------*/
  32.  
  33. void    ZClipboard::PutData( OSType dataType, Handle someData )
  34. {
  35.     FailNILParam( someData );
  36.     
  37.     long    len = GetHandleSize( someData );
  38.     char    hs = HGetState( someData );
  39.     
  40.     HLock( someData );
  41.     PutData( dataType, *someData, len );
  42.     HSetState( someData, hs );
  43. }
  44.  
  45. /*----------------------------------***  PUTDATA  ***-----------------------------------*/
  46. /*    
  47. put arbitrary data on the clipboard with the type supplied
  48. ----------------------------------------------------------------------------------------*/
  49.  
  50. void    ZClipboard::PutData( OSType dataType, Ptr dataPtr, const long dataLen )
  51. {
  52.     Clear();
  53.     AppendData( dataType, dataPtr, dataLen );
  54.     
  55.     SendMessage( clipContentsChanged, (void*) dataType );
  56. }
  57.  
  58.  
  59. /*----------------------------------***  PUTDATA  ***-----------------------------------*/
  60. /*    
  61. put the picture on the clipboard with the type 'PICT'
  62. ----------------------------------------------------------------------------------------*/
  63.  
  64. void    ZClipboard::PutData( PicHandle aPicture )
  65. {
  66.     PutData( 'PICT', (Handle) aPicture );
  67. }
  68.  
  69. /*----------------------------------***  PUTTEXT  ***-----------------------------------*/
  70. /*    
  71. put the text on the clipboard with the type 'TEXT'
  72. ----------------------------------------------------------------------------------------*/
  73.  
  74. void    ZClipboard::PutText( Handle textH )
  75. {
  76.     PutData( 'TEXT', textH );
  77. }
  78.  
  79. /*----------------------------------***  PUTTEXT  ***-----------------------------------*/
  80. /*    
  81. put the text in an arbitrary buffer on the clipboard with the type 'TEXT'
  82. ----------------------------------------------------------------------------------------*/
  83.  
  84. void    ZClipboard::PutText( Ptr charBuf, const long textLen )
  85. {
  86.     Clear();
  87.     AppendText( charBuf, textLen );
  88. }
  89.  
  90.  
  91. /*----------------------------------***  APPENDDATA  ***--------------------------------*/
  92. /*    
  93. add the data to the clipboard with the type supplied
  94. ----------------------------------------------------------------------------------------*/
  95.  
  96. void    ZClipboard::AppendData( OSType dataType, Handle someData )
  97. {
  98.     FailNILParam( someData );
  99.     
  100.     long    len = GetHandleSize( someData );
  101.     char    hs = HGetState( someData );
  102.     
  103.     HLock( someData );
  104.     AppendData( dataType, *someData, len );
  105.     HSetState( someData, hs );
  106.     
  107.     SendMessage( clipContentsAppended, (void*) dataType );
  108. }
  109.  
  110. /*----------------------------------***  APPENDDATA  ***--------------------------------*/
  111. /*    
  112. add the arbitrary data to the clipboard with the type supplied
  113. ----------------------------------------------------------------------------------------*/
  114.  
  115. void    ZClipboard::AppendData( OSType dataType, Ptr dataPtr, const long dataLen )
  116. {
  117.     FailOSErr( PutScrap( dataLen, dataType, dataPtr ));
  118. }
  119.  
  120. /*----------------------------------***  APPENDDATA  ***--------------------------------*/
  121. /*    
  122. add the picture to the clipboard with the type 'PICT'
  123. ----------------------------------------------------------------------------------------*/
  124.  
  125. void    ZClipboard::AppendData( PicHandle aPicture )
  126. {
  127.     AppendData( 'PICT', (Handle) aPicture );
  128. }
  129.  
  130. /*----------------------------------***  APPENDTEXT  ***--------------------------------*/
  131. /*    
  132. add the text to the clipboard with the type 'TEXT'
  133. ----------------------------------------------------------------------------------------*/
  134.  
  135. void    ZClipboard::AppendText( Handle textH )
  136. {
  137.     AppendData( 'TEXT', textH );
  138. }
  139.  
  140.  
  141. /*----------------------------------***  APPENDTEXT  ***--------------------------------*/
  142. /*    
  143. add the text in an arbitrary buffer to the clipboard with the type 'TEXT'
  144. ----------------------------------------------------------------------------------------*/
  145.  
  146. void    ZClipboard::AppendText( Ptr charBuf, const long textLen )
  147. {
  148.     Handle t;
  149.     
  150.     FailOSErr( PtrToHand( charBuf, &t, textLen ));
  151.     
  152.     try
  153.     {
  154.         AppendText( t );
  155.     }
  156.     catch( OSErr err )
  157.     {
  158.         DisposeHandle( t );
  159.         
  160.         throw err;
  161.     }
  162.     
  163.     DisposeHandle( t );
  164. }
  165.  
  166. /*-------------------------------------***  CLEAR  ***----------------------------------*/
  167. /*    
  168. make the clipboard empty
  169. ----------------------------------------------------------------------------------------*/
  170.  
  171. void    ZClipboard::Clear()
  172. {
  173.     FailOSErr( ZeroScrap());
  174.     
  175.     SendMessage( clipContentsCleared, NULL );
  176. }
  177.  
  178. /*------------------------------------***  GETDATA  ***---------------------------------*/
  179. /*    
  180. get the data from the clipboard with the type requested
  181. ----------------------------------------------------------------------------------------*/
  182.  
  183. Handle    ZClipboard::GetData( OSType dataType )
  184. {
  185.     Handle    h = NULL;
  186.     long    result, offset;
  187.     
  188.     if ( QueryType( dataType ))
  189.     {
  190.         FailNIL( h = NewHandle( 0 ));
  191.     
  192.         result = GetScrap( h, dataType, &offset);
  193.         
  194.         if (result <= 0)
  195.         {
  196.             DisposeHandle( h );
  197.             FailOSErr( noTypeErr );
  198.         }
  199.     }
  200.     
  201.     return h;
  202. }
  203.  
  204.  
  205. /*----------------------------------***  QUERYTYPE  ***---------------------------------*/
  206. /*    
  207. does the clipboard have this data type?
  208. ----------------------------------------------------------------------------------------*/
  209.  
  210. Boolean ZClipboard::QueryType( OSType dataType )
  211. {
  212.     long    result, offset;
  213.     
  214.     result = GetScrap( NULL, dataType, &offset );
  215.     
  216.     return ( result > 0 );
  217. }
  218.  
  219. /*----------------------------------***  GETDATASIZE  ***-------------------------------*/
  220. /*    
  221. how big is the data of this type?
  222. ----------------------------------------------------------------------------------------*/
  223.  
  224. long    ZClipboard::GetDataSize( OSType dataType )
  225. {
  226.     long    result, offset;
  227.     
  228.     result = GetScrap( NULL, dataType, &offset );
  229.     
  230.     if ( result > 0 )
  231.         return result;
  232.     else
  233.         return -1;
  234. }
  235.  
  236. /*--------------------------------***  GETCLIPSTATUS  ***-------------------------------*/
  237. /*    
  238. what state is the clipboard in?
  239. ----------------------------------------------------------------------------------------*/
  240.  
  241. short    ZClipboard::GetClipStatus()
  242. {
  243.     PScrapStuff    ps;
  244.     
  245.     ps = InfoScrap();
  246.     
  247.     return ps->scrapCount;
  248. }
  249.  
  250.